﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Configuration;

namespace HoaDon
{
	public static class CommonFunction
	{
		public static string GetReportType(string reportID)
		{
			DataTable dt = new DataTable();
			dt = SqlEXEC.GetData(WebConfigurationManager.ConnectionStrings["proxyconn"].ConnectionString, "SELECT Type FROM reportuser WHERE FK_UserID = '" + System.Web.HttpContext.Current.User.Identity.Name.ToUpper() + "' AND FK_ReportID = '" + reportID + "'");
			if (dt.Rows.Count > 0)
				return dt.Rows[0]["Type"].ToString();
			else
				return "0";
		}

		public static void SetReportType(string reportID, string reportType)
		{
			SqlEXEC.ExecCommand(WebConfigurationManager.ConnectionStrings["proxyconn"].ConnectionString, "DELETE FROM reportuser WHERE FK_UserID = '" + System.Web.HttpContext.Current.User.Identity.Name.ToUpper() + "' AND FK_ReportID = '" + reportID + "'");
			SqlEXEC.ExecCommand(WebConfigurationManager.ConnectionStrings["proxyconn"].ConnectionString, "INSERT INTO reportuser (FK_UserID, FK_ReportID, Type) VALUES('" + System.Web.HttpContext.Current.User.Identity.Name.ToUpper() + "','" + reportID + "','" + reportType + "')");
		}
	}
}
